package com.zhiwei.msf.common.filter;

import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import com.zhiwei.msf.common.constant.HttpConstants;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ZHIWEI.YANG
 * @time 2019/11/24 - 16:48
 * @decription 默认过滤器配置
 */
@Component
public class EncodingFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        request.setCharacterEncoding(HttpConstants.ENCODING);
        response.setCharacterEncoding(HttpConstants.ENCODING);
        response.setContentType(HttpConstants.RESPONSE_CONTENT_TYPE);
        filterChain.doFilter(request, response);
    }
}
